package com.yy.job.console.converter;

import java.util.List;
import java.util.stream.Collectors;

import org.springframework.beans.BeanUtils;

import com.yy.job.common.dao.po.YYJobDO;
import com.yy.job.common.enums.JobStatusEnum;
import com.yy.job.common.utils.date.YYDateUtils;
import com.yy.job.console.dto.JobView;

public class JobViewConverter {

	public static JobView convert(YYJobDO jobDO) {
		JobView consoleDTO = new JobView();
		BeanUtils.copyProperties(jobDO, consoleDTO);
		consoleDTO.setExecTimeFormat(YYDateUtils.formatDateTimeDefault(jobDO.getExecTime()));
		consoleDTO.setExpectedStartTimeFormat(YYDateUtils.formatDateTimeDefault(jobDO.getExpectedStartTime()));
		consoleDTO.setGmtCreatedFormat(YYDateUtils.formatDateTimeDefault(jobDO.getGmtCreated()));
		JobStatusEnum jobStatusEnum = JobStatusEnum.findByCode(jobDO.getJobStatus());
		if(jobStatusEnum != null) {
			consoleDTO.setJobStatusName(jobStatusEnum.getName());
		}
		return consoleDTO;
	}

	public static List<JobView> listConvert(List<YYJobDO> jobDOs) {
		if (jobDOs == null) {
			return null;
		}
		return jobDOs.stream().map(e -> convert(e)).collect(Collectors.toList());
	}

}
